package com.gxa.autoparts.core.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author R
 * @data 2021-12-07 9:44
 */
public class TimeUtil {

    public static String rollBackTime(String cycle){
        Calendar calendar = Calendar.getInstance();
        Date data = new Date();
        String format = null;
        calendar.setTime(data);
        if (cycle.equals("近一周")){
            calendar.add(Calendar.DATE,-7);
        }else if (cycle.equals("近一月")){
            calendar.add(Calendar.MONTH,-1);
        }else {
            calendar.add(Calendar.YEAR,-1);
        }
        Date time = calendar.getTime();
        format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time);
        return format;
    }

    public static String timeFormat(Date date){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
}
